import {createSlice} from "@reduxjs/toolkit";
import axios from "axios";


const channelStore=createSlice({
    name:'channel',
    initialState:{
        channelList:[]
    },
    reducers:{
        setChannels(state,action){
            state.channelList=action.payload;
        }
    }
})
// 异步请求部分
const {setChannels}=channelStore.actions;
// 这个是异步请求的模板代码
const fetchChannelList=()=>{
    return async (dispatch)=>{
        const res=await axios.get('http://geek.itheima.net/v1_0/channels');
        dispatch(setChannels(res.data.data.channels));
    }
}
const channelsReducer=channelStore.reducer;
export {setChannels,fetchChannelList}
export default channelsReducer;


